﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace STAR.Spring.Framework.Module.Core
{
    /// <summary>
    /// 对于使用自定义请求的辅助类
    /// </summary>
    public class CustomProcessHelper
    {
        /// <summary>
        /// 数据层辅助
        /// </summary>
        /// <param name="requestName"></param>
        /// <param name="parms"></param>
        /// <returns></returns>
        public static DataSet GetDataSet(string requestName, object[] parms)
        {
            return DBProcess.GetDataSet(requestName, parms);
        }

        /// <summary>
        /// 数据转实体辅助
        /// </summary>
        /// <param name="dt"></param>
        /// <param name="requestType"></param>
        /// <returns></returns>
        public static dynamic CreateResult(DataTable dt,ReturnDataType requestType)
        {
            dynamic mainData = null;

            switch (requestType)
            {
                case ReturnDataType.单值:
                    if (dt.Rows.Count > 0)
                    {
                        return mainData = dt.Rows[0][0].ToString();
                    }
                    break;
                case ReturnDataType.对象:
                    mainData = Founder.PKURG.Common.Core.CustomMapping.GetObject(dt);
                    break;
                case ReturnDataType.列表:
                    mainData = Founder.PKURG.Common.Core.CustomMapping.GetList(dt);
                    break;
                default:
                    break;
            }
            return mainData;
        }
    }
}
